package Module::Changes::Formatter::YAML;

use warnings;
use strict;
use YAML;
use DateTime::Format::W3CDTF;


our $VERSION = '0.06';


use base 'Module::Changes::Formatter';


sub format {
    my ($self, $changes) = @_;

    my %format = ( global => { name => $changes->name } );

    for my $release ($changes->releases) {
        push @{ $format{releases} } => {
            version => $release->version_as_string,
            date    => DateTime::Format::W3CDTF->new->format_datetime(
                        $release->date
                    ),
            author  => $release->author,
            changes => scalar($release->changes),
            tags    => scalar($release->tags),
        };
    }

    Dump \%format;
}


1;

__END__

{% USE p = PodGenerated %}

=head1 NAME

Module::Changes::Formatter::YAML - format a Changes object as YAML

=head1 SYNOPSIS

    use Module::Changes;
    my $formatter = Module::Changes->make_object_for_type('formatter_yaml');
    $formatter->format($changes);

=head1 DESCRIPTION

This class can format a Changes object as YAML. The layout of the YAML file is
documented in L<Module::Changes>.

=head1 METHODS

=over 4

{% p.write_methods %}

=item format

    print $formatter->format($changes);

Takes a changes object and formats it as YAML, then returns the result string.

=back

{% p.write_inheritance %}

{% PROCESS standard_pod %}

=cut

